package ExceptionTest;

/**
 * @author zyc
 * @create 2022--05--11 17:09
 */
public class test implements Compute{


    public static void main(String []args) throws MyException {
        test test = new test();
        int result = test.sum(1, 2);			//调用Sum()方法
        System.out.println(result);			//将Sum()方法的返回值输出
    }

    @Override
    public int sum(int num1, int num2) throws MyException {
        if(num1<0||num2<0){						//判断方法中参数是否满足条件
            throw new MyException("输入参数为负数"); //错误信息
        }
        if(num1>20||num2>20){					//判断方法中参数是否满足条件
            throw new MyException("输入参数大于20");//错误信息
        }
        return (num1+num2);
    }
}
